import {Component, OnInit, Inject, ViewChild} from '@angular/core';
import {User} from '../../models/User';
import {AssetService} from '../../service/AssetService';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material';
import {Asset} from '../../models/Asset';
import { NgForm, FormControl } from '@angular/forms';
import { Deliver } from '../../models/Deliver';
import {DeliverService} from '../../service/DeliverService';

@Component({
  templateUrl: './assignUpdate.html',
  styleUrls: ['./assignUpdate.css']
})
export class AssignUpdateComponent implements OnInit {
  users: User[];
  assetInfo: Asset;
  deliver: Deliver;
  constructor(
    private dialogRef: MatDialogRef<AssignUpdateComponent>,
    private assetService: AssetService,
    private  deliverService: DeliverService,
    // users：下拉框
    // asset: 要展示的值
    @Inject(MAT_DIALOG_DATA) public data: {asset: Asset, users: User[]}
  ) {
    this.users = data.users;
    this.assetInfo =  data.asset;
    this.deliver = {
      assetid : this.assetInfo.id,
      old_userid: this.assetInfo.sysUser.id
    };
  }
  ngOnInit() {
  }
  onSubmit() {
    this.deliverService.create(this.deliver).subscribe((res) => {
      this.dialogRef.close(res.res);
    });
  }
}
